package fhq.hcmute.edu.vn.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import fhq.hcmute.edu.vn.activities.R;

/**
 * @author Hien Nguyen Oct 5, 2012
 */
public class WiFiAdapter extends ArrayAdapter<WiFiItem> {

	private Activity context;
	private List<WiFiItem> wiFiItems;

	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public WiFiAdapter(Activity context, List<WiFiItem> objects) {
		super(context, R.layout.listview_wifi_item, objects);
		this.context = context;
		this.wiFiItems = objects;
	}

	public final List<WiFiItem> getWiFiItems() {
		return wiFiItems;
	}

	public final void setWiFiItems(List<WiFiItem> wiFiItems) {
		this.wiFiItems = wiFiItems;
	}

	static class ViewHolder {
		private TextView txtName;
		private TextView txtSecurityType;
		private ImageView imgSignalStrength;
	}

	@Override
	public final View getView(int position,
			View convertView, ViewGroup parent) {
		View row = convertView;
		if (convertView == null) {
			LayoutInflater inflater = this.context.getLayoutInflater();
			ViewHolder holder = new ViewHolder();
			row = inflater.inflate(R.layout.listview_wifi_item, null);
			holder.txtName = (TextView) row.findViewById(R.id.lblName);
			holder.txtSecurityType =
					(TextView) row.findViewById(R.id.txtSecurityType);
			holder.imgSignalStrength =
					(ImageView) row.findViewById(R.id.imgSignalStrength);
			row.setTag(holder);
		}
		ViewHolder holder = (ViewHolder) row.getTag();
		holder.txtName.setText(wiFiItems.get(position).getName());
		holder.txtSecurityType.setText(wiFiItems.get(position)
				.getCapabilities());
		holder.imgSignalStrength.setImageResource(wiFiItems.get(position)
				.getSignal());
		return row;
	}
}
